#!/usr/bin/env python

import os, sys

def usage():
    print 'Usage:', sys.argv[0], '<directory>'
    sys.exit(1)

def listify(dir, level=1, indent='  '):
    lines = []
    for item in os.listdir(dir):
        if item.startswith('.') or item.endswith('~'):
            continue
        path = ''.join([dir, os.sep, item])
        padding = indent * level
        lines.append('%s<li>' % padding)
        lines.append('%s<a href="%s">%s</a>' % (padding + indent, path, item))
        if os.path.isdir(path):
            lines.append('%s<ul>' % (padding + indent))
            lines.append(listify(path, level + 2))
            lines.append('%s</ul>' % (padding + indent))
        lines.append('%s</li>' % padding)
    return '\n'.join(lines)

try:
    dir = sys.argv[1].rstrip(os.sep)
    print '\n'.join(['<ul>', listify(dir), '</ul>'])
except:
    usage()
